<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="制具SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolSn']" placeholder="请输入制具SN"></a-input>
        </a-form-item>
        <a-form-item label="制具料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolCode']" placeholder="请输入制具料号"></a-input>
        </a-form-item>
        <a-form-item label="制具名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maketoolName']" placeholder="请输入制具名称"></a-input>
        </a-form-item>
        <a-form-item label="操作类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['operationType']" placeholder="请输入操作类型"></a-input>
        </a-form-item>
        <a-form-item label="不良代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['badCode']" placeholder="请输入不良代码"></a-input>
        </a-form-item>
        <a-form-item label="不良描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['badDescription']" placeholder="请输入不良描述"></a-input>
        </a-form-item>
        <a-form-item label="保养/维修人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['maintainPerson']" placeholder="请输入保养/维修人"></a-input>
        </a-form-item>
        <a-form-item label="确认人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['confirmPerson']" placeholder="请输入确认人"></a-input>
        </a-form-item>
        <a-form-item label="报修人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['reportFixperson']" placeholder="请输入报修人"></a-input>
        </a-form-item>
        <a-form-item label="左上张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['leftupPower']" placeholder="请输入左上张力"></a-input>
        </a-form-item>
        <a-form-item label="右上张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rightupPower']" placeholder="请输入右上张力"></a-input>
        </a-form-item>
        <a-form-item label="中间张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['middlePower']" placeholder="请输入中间张力"></a-input>
        </a-form-item>
        <a-form-item label="左下张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['leftdownPower']" placeholder="请输入左下张力"></a-input>
        </a-form-item>
        <a-form-item label="右下张力" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['rightdownPower']" placeholder="请输入右下张力"></a-input>
        </a-form-item>
        <a-form-item label="张力差异" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['powerGap']" placeholder="请输入张力差异"></a-input>
        </a-form-item>
        <a-form-item label="厚度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['thickDegree']" placeholder="请输入厚度"></a-input>
        </a-form-item>
        <a-form-item label="平整度" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['flattenDegree']" placeholder="请输入平整度"></a-input>
        </a-form-item>
        <a-form-item label="保养/维修内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['maintainContent']" rows="4" placeholder="请输入保养/维修内容"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'


  export default {
    name: "MesSingletoolMaintainModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/produce/mesSingletoolMaintain/add",
          edit: "/produce/mesSingletoolMaintain/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'maketoolSn','maketoolCode','maketoolName','operationType','badCode','badDescription','maintainPerson','confirmPerson','reportFixperson','leftupPower','rightupPower','middlePower','leftdownPower','rightdownPower','powerGap','thickDegree','flattenDegree','maintainContent'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'maketoolSn','maketoolCode','maketoolName','operationType','badCode','badDescription','maintainPerson','confirmPerson','reportFixperson','leftupPower','rightupPower','middlePower','leftdownPower','rightdownPower','powerGap','thickDegree','flattenDegree','maintainContent'))
      },

      
    }
  }
</script>